<template>
  <div class="app-container">
    <div class="search-container">
      <el-form inline>
        <el-form-item label="名称">
          <el-input />
        </el-form-item>
        <el-button type="primary">搜索</el-button>
        <el-button type="primary" @click="operate('add')">新增</el-button>
        <el-button type="primary">导入</el-button>
        <el-button type="primary">导出</el-button>
      </el-form>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="巡检名称">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="类目">
        <template slot-scope="scope">
          {{ scope.row.type }}
        </template>
      </el-table-column>
      <el-table-column label="地点">
        <template slot-scope="scope">
          {{ scope.row.place }}
        </template>
      </el-table-column>
      <el-table-column label="巡检人" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡检时间" width="200" align="center">
        <template slot-scope="scope">
          {{ scope.row.display_time }}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="状态" width="110" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status | statusFilterLabel }}</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" prop="created_at" label="Display_time" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.display_time }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" width="310" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" :disabled="scope.row.status == 0">发布</el-button>
          <el-button type="warning" size="mini" :disabled="scope.row.status == 1">停用</el-button>
          <el-button type="success" size="mini">修改</el-button>
          <el-button type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" :title="title" width="800px">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="巡检计划名称">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="巡查人">
          <el-select v-model="form.person" placeholder="请选择巡查人">
            <el-option v-for="(item, index) in personList" :key="index" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="类目">
          <el-select v-model="form.region" placeholder="请选择类目">
            <el-option v-for="(item, index) in typeList" :key="index" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查频次">
          <el-select v-model="form.num" placeholder="请选择巡查人">
            <el-option v-for="(item, index) in numList" :key="index" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="巡查时间">
          <el-col :span="11">
            <el-date-picker v-model="form.date1" type="date" placeholder="选择日期" style="width: 100%;" />
          </el-col>
          <el-col :span="2" class="line">-</el-col>
          <el-col :span="11">
            <el-time-picker v-model="form.date2" type="fixed-time" placeholder="选择时间" style="width: 100%;" />
          </el-col>
        </el-form-item>
        <el-form-item label="是否发布">
          <el-switch v-model="form.delivery" />
        </el-form-item>

        <!-- <el-form-item label="Resources">
          <el-radio-group v-model="form.resource">
            <el-radio label="Sponsor" />
            <el-radio label="Venue" />
          </el-radio-group>
        </el-form-item>
        <el-form-item label="Activity form">
          <el-input v-model="form.desc" type="textarea" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
          <el-button @click="onCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: 'success',
        1: 'gray',
        2: 'danger'
      }
      return statusMap[status]
    },
    statusFilterLabel(status) {
      const statusMap = {
        0: '已发布',
        1: '未发布',
        2: '暂停中'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      data: [{
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 0,
        place: '1273621637521463'
      }, {
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 1,
        place: '1273621637521463'
      }, {
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 2,
        place: '1273621637521463'
      }],
      dialogVisible: false,
      title: '新增巡检计划',
      personList: [{ label: '张三', value: '0' }],
      numList: [{ label: '每年', value: '0' }, { label: '每月', value: '1' }, { label: '每日', value: '2' }],
      typeList: [{ label: '消防安全', value: '0' }, { label: '食堂安全', value: '1' }, { label: '护工查房', value: '2' }],
      form: {
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      this.list = this.data
      this.listLoading = false
      // getList().then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    },
    operate(type) {
      if (type === 'add') {
        this.dialogVisible = true
      }
    },
    onSubmit() {
      this.$message('submit!')
    },
    onCancel() {
      this.dialogVisible = false
    }
  }
}
</script>
<style scoped>
.line {
  text-align: center;
}
</style>
